new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Start_Date: '',
        End_Date: '',
        Category_SerialNumber: '',
        Supplier_SerialNumber: '',
        Store_SerialNumber: '',
        token: $.cookie("token"),
        page: 1,			//页数
        limit: 10,		//每页数据条数
      },
      form1: {
        Start_Date: '',
        End_Date: '',
        Article_Name: '',
        Row_Status: '',
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        token: $.cookie("token"),
        page: 1,			//页数
        limit: 10,		//每页数据条数
      },
      total: 0,// 总条数
      radio: '',
      formData: {},
      activeName: '',
      category: [],//分类查询--类别
      supplier: [],//分类查询--供应商
      tableData: [],		//表格数据
      store: [],
      price: {},
      Total_sales: {
        Enterprises_Number: 0,
      },
      loading: false,//节流
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      time: '',

    }
  },
  mounted() {
    this.getList();
    // this.getData(this.form);

  },
  computed: {
    formatTime1() {
      return function (times) {
        if (times) {
          let date = new Date(times);
          let year = date.getFullYear();
          let month = date.getMonth() + 1;
          let day = date.getDate();
          if (month < 10) {
            month = "0" + month;
          }
          if (day < 10) {
            "0" + day
          }
          return `${year}-${month}-${day}`;
        } else { return '' }
      }
    },
    //去.0
    ZeroRemoval() {
      return function (params) {
        params = params.replace('.0', '')
        return params
      }
    },
    //千分位处理
    thousands() {
      return function (params) {
        params = Number(params).toFixed(2)
        return params.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
      }
    },
    //百分比处理
    toPercent() {
      return function (point) {
        point = Number(point * 100).toFixed(2);
        return point += "%";
      }
    },
  },
  methods: {
    getData(data) {
      let _this = this;
      $.ajax({
        type: 'POST',
        url: DomainName + "/getReconciliationPrice1Action",
        data,
        success: function (res) {
          _this.tableData = res.Data.tabledata
          _this.price = res.Total
          _this.total = res.Data.limit
          console.log(res);
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    accAdd(arg1, arg2) {	//浮点型相加
      var r1, r2, m;
      try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
      try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
      m = Math.pow(10, Math.max(r1, r2))
      return (arg1 * m + arg2 * m) / m
    },
    getList() {
      let _this = this
      //获取门店名称
      $.ajax({
        type: 'POST',
        url: DomainName + "/getInquiryAction",
        data: {
          Data: "store_info",
          Enterprise_Info_SerialNumber: _this.form.Enterprise_Info_SerialNumber,
          token: $.cookie("token")
        },
        success: function (res) {
          _this.store = res
          // res.forEach(item => {
          //   _this.store.push(item)
          //   _this.listitem.push(item.Store_SerialNumber)
          // })
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
      //获取类别
      $.ajax({
        type: 'POST',
        url: DomainName + "/GoodsFileInquiry",
        data: {
          Data: "category",
          token: $.cookie("token")
        },
        success: function (res) {
          _this.category = res
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
      //获取供应商
      $.ajax({
        type: 'POST',
        url: DomainName + "/getInquiryAction",
        data: {
          Data: "supplier_info",
          Enterprise_Info_SerialNumber: _this.form.Enterprise_Info_SerialNumber,
          token: $.cookie("token")
        },
        success: function (res) {
          _this.supplier = res
          let ress = {
            data: ['货拉拉2', '货拉拉', '货拉拉7', '火辣辣', '货拉拉3', '货拉拉4', '货拉拉5', '货拉拉6', '货拉拉7', '货拉拉8', '货拉拉9'],
            series: [
              {
                name: '火辣辣',
                data: [820, 932, 901, 934, 1290, 1330, 1320, 123, 458, 548, 2364, 545],
                type: 'line',
              },
              {
                name: '货拉拉',
                data: [82, 932, 90, 93, 129, 133, 132, 1290, 1330, 1320, 482, 123],
                type: 'line',
              },
              {
                name: '货拉拉1',
                data: [82, 932, 900, 93, 129, 1332, 1321, 1290, 1330, 1320, 4822, 123],
                type: 'line',
              },
              {
                name: '货拉拉2',
                data: [82, 932, 90, 93, 129, 1313, 1322, 1290, 1330, 1320, 4823, 123],
                type: 'line',
              },
              {
                name: '货拉拉3',
                data: [822, 932, 910, 93, 129, 133, 122, 1290, 133, 1320, 4823, 123],
                type: 'line',
              },
              {
                name: '货拉拉4',
                data: [822, 932, 910, 93, 129, 133, 122, 1290, 133, 1320, 4823, 123],
                type: 'line',
              },
              {
                name: '货拉拉5',
                data: [822, 932, 910, 93, 129, 133, 122, 1290, 133, 1320, 4823, 123],
                type: 'line',
              },
              {
                name: '货拉拉6',
                data: [822, 932, 910, 93, 129, 133, 122, 1290, 133, 1320, 4823, 123],
                type: 'line'
              },
              {
                name: '货拉拉7',
                data: [822, 932, 910, 93, 129, 133, 122, 1290, 133, 1320, 4823, 123],
                type: 'line',
              },
              {
                name: '货拉拉8',
                data: [822, 932, 910, 93, 129, 133, 122, 1290, 133, 1320, 4823, 123],
                type: 'line',
              },
              {
                name: '货拉拉9',
                data: [822, 932, 910, 93, 129, 133, 122, 1290, 133, 1320, 4823, 123],
                type: 'line',
              }
            ]
          }
          _this.mychart(ress)
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    // 折线图
    mychart(ress) {
      // 初始化
      var myChart = echarts.init(document.getElementById('SalesVolume'));
      option = {
        xAxis: {
          type: 'category',
          data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
        },
        yAxis: {
          type: 'value'
        },
        // 顶部名称
        legend: {
          data: ress.data
        },
        // 悬浮提示
        tooltip: {
          trigger: 'axis'
        },
        series: ress.series
      };
      // 调用渲染
      myChart.setOption(option);
      window.addEventListener('resize', function () {
        myChart.resize()
      })
    },
    //表格展开
    handleChildren(row) {
      console.log(row.Children.article_info);
      _this = this
      $.ajax({
        url: DomainName + '/getReconciliationPriceDetailAction',
        type: 'POST',
        data: {
          Article_SerialNumber: row.Article_SerialNumber,
          Supplier_SerialNumber: row.Supplier_SerialNumber,
          token: $.cookie("token")
        },
        success: function (data) {
          row.Children.article_info = data
          console.log(row.Children.article_info);
        },
        dataType: "json"
      });
      // }

    },
    // 改变日期
    DateChange() {
      this.form.Start_Date = this.time[0]
      this.form.End_Date = this.time[1]
      console.log(this.form.Start_Date, this.form.End_Date)
      this.radio == '0'
      this.getData(this.form);
    },
    handlechange() {
      if (this.radio == '1') {
        this.form.Start_Date = this.formatTime1(new Date().getTime() - 60 * 60 * 24 * 365 * 1000) + ' 15:00:00',
          this.form.End_Date = this.formatTime1(new Date().getTime()) + ' 15:00:00',
          this.getData(this.form);
      } else if (this.radio == '2') {
        this.form.Start_Date = this.formatTime1(new Date().getTime() - 60 * 60 * 24 * 30 * 1000) + ' 15:00:00',
          this.form.End_Date = this.formatTime1(new Date().getTime()) + ' 15:00:00',
          this.getData(this.form);
      } else if (this.radio == '3') {
        this.form.Start_Date = this.formatTime1(new Date().getTime() - 60 * 60 * 24 * 1000) + ' 15:00:00',
          this.form.End_Date = this.formatTime1(new Date().getTime()) + ' 15:00:00',
          this.getData(this.form);
      }
    },
    handleclassify() {//分类查询
      this.getData(this.form);
    },
    handleSizeChange(val) {//分页查询
      this.form.page = 1;
      this.form.limit = val;
      this.getData(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getData(this.form)
    },
  }
})